﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GmInplaceEdit.h"
#include "NdbObjectSchematic.h"
#include "IExternalData.h"
#include "DbDataSchema.h"

namespace gcmp
{
    class IModelView;

    class GM_INPLACE_EDIT_EXPORT InplaceEditModelViewProjectData : public NdbObjectSchematic, public IExternalData
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, InplaceEditModelViewProjectData, gcmp::NdbObjectSchematic, EFE4DF76 - 1707 - 4A74 - B137 - FE1CD68BB813, gminplaceedit, IExternalData)
            DATA_TRANSIENT(IElement*, pOwnerElement)
            DATA(Bool, IsRequestingData)  // 是否正在请求项目视图数据
            DATA(Bool, IsRequestedData)   // 项目视图数据是否已存在
        DBOBJECT_DATA_END

    public:
        static const InplaceEditModelViewProjectData* Get(const IModelView* pModelView);
        static InplaceEditModelViewProjectData* GetFw(IModelView* pModelView);

        bool GetIsRequestingData() const { return GetIsRequestingData__(); }
        void SetIsRequestingData(bool isRequestingData)
        {
            SetIsRequestedData__(false);
            SetIsRequestingData__(isRequestingData);
        }

        bool GetIsRequestedData() const { return GetIsRequestedData__(); }
        void SetIsRequestedData(bool isRequestedData)
        {
            SetIsRequestingData__(false);
            SetIsRequestedData__(isRequestedData);
        }

        virtual bool SetOwnerElement(IElement* pOwnerElement) override
        {
            m_pOwnerElement = pOwnerElement;
            return true;
        }
        virtual IElement* GetOwnerElement() override { return m_pOwnerElement; }
        virtual const IElement* GetOwnerElement() const override { return m_pOwnerElement; }

    public:
        virtual void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds) override;
        virtual void ReportParents(IElementParentReporter& reporter) const override;
        virtual void GetCalculators(ICalculatorCollection* calculators) const override;

        virtual void ReportParameterDefinitions(std::vector<int>* pParamDefIds) const override;
        virtual gcmp::OwnerPtr<IParameter> GetNativeParameter(int paramDefId) const override;
        virtual bool SetNativeParameter(const IParameter* param, std::wstring* errorMsg = nullptr) override;
        virtual bool IsParameterModifiable(int paramDefId) const override;

        virtual void Report(const gcmp::ICopyContext & copyContext, gcmp::ICopyStrategyReporter& reporter) const override;
        virtual void UpdateAfterCopy(const ICopyContext& copyContext) override {};
        virtual void UpdateForWeakParentCopied(const IDocument* pDocumentFrom, const IElement* pSource, const IElement* pCopy) const override {};
        virtual bool ShouldBeCopiedTogether(const ICopyContext & copyContext) const override { return true; };
        virtual bool IsStrongParentsNeedCopied(void) const override { return true; };
        virtual bool CanBeCopied(std::wstring* pErrorMessage) const override { return true; };
        virtual bool Transform(const Matrix4d& matrix) override { return true; }

    private:
        IDocument* GetDocument() const;
        ElementId GetOwnerElementId() const;
        virtual NdbObject* GetTopOwnerObject() const override;
    };
}
